<?php
  class UserController extends Controller{
    public function SignUpAction(){
      $this->view->set_tpl('SignUp');
    }
    public function LeaveAction(){
      $um = new UserMapper();
      
      $um->forgot();
      $this->view->set_tpl('Leave');
    }
    public function SignInAction(){
      $this->view->set_tpl('SignIn');
      
    }   
    public function createUserAction(){
      $um = new UserMapper();
      $newUser = new UserModel();

      $newUser->set_name($_REQUEST['username'])
              ->set_password($_REQUEST['password']);
      $um->createUser($newUser);
      $um->autoLoginNewUser();
      $this->view->set_tpl('AfterSignIn');
    }
    public function loginAction(){
      $um = new UserMapper();
      $user = new UserModel();
      // Validate user input
      $user->set_name($_REQUEST['username'])
           ->set_password($_REQUEST['password']);

      if(!$um->isRealUser($user)){
        $this->view->loginError=true;
        $this->view->set_tpl('SignIn');
      }else{
        $this->view->set_tpl('AfterSignIn');
      }
    }
  }
?>
